package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.UserCoupon;
import com.sxkf.template.service.UserCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.util.CheckEmptyUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 用户优惠卷 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-12-02 18:10:34
 *
 */
@Api(tags = "用户优惠券模块")
@RestController
@RequestMapping("/userCoupon")
public class UserCouponController {
    @Resource
    private UserCouponService userCouponService;

    @PostMapping("/list")
    @ApiOperation("查询用户优惠券")
    public R<List<UserCoupon>> list(@RequestParam @NotNull String userId, @RequestParam(required = false) String state) {
        return R.success(userCouponService.list(new LambdaQueryWrapper<UserCoupon>()
                .eq(UserCoupon::getUserId,userId)
                .eq(!CheckEmptyUtil.isEmpty(state),UserCoupon::getState,state)));
    }

    @PostMapping("/receive")
    @ApiOperation("用户领取优惠券")
    public R<?> receive(@RequestParam String userId, @RequestParam String couponId) {
        userCouponService.userReceiveCoupon(userId, couponId);
        return R.success();
    }
}
